package com.wormhole.wormholemanagement.controller;

import com.wormhole.wormholemanagement.dto.PositionDTO;
import com.wormhole.wormholemanagement.entity.Position;
import com.wormhole.wormholemanagement.service.PositionService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api/positions")
@RequiredArgsConstructor
public class PositionController {

    private final PositionService positionService;

    @GetMapping
    public ResponseEntity<List<PositionDTO>> getAllPositions() {
        List<Position> positions = positionService.getAllPositions();
        List<PositionDTO> dtos = positions.stream()
                .map(PositionDTO::new)
                .collect(Collectors.toList());
        return ResponseEntity.ok(dtos);
    }
}